﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Map
{
    public struct GeoPoint
    {
        public static readonly GeoPoint Null = new GeoPoint(double.PositiveInfinity, double.PositiveInfinity);
        public double Latitude { get; set; }
        public double Longitude { get; set; }

        public GeoPoint(double lat, double lon) : this()
        {
            Latitude = lat;
            Longitude = lon;
        }

        public override string ToString()
        {
            return string.Format("{0}, {1}", Latitude, Longitude);
        }

        public static bool operator ==(GeoPoint left, GeoPoint right)
        {
            return left.Longitude == right.Longitude && left.Latitude == right.Latitude;
        }

        public static bool operator !=(GeoPoint left, GeoPoint right)
        {
            return left.Longitude != right.Longitude || left.Latitude != right.Latitude;
        }
        public override bool Equals(object obj)
        {
            GeoPoint other = (GeoPoint)obj;
            return this == other;
        }

        public override int GetHashCode()
        {
            return Latitude.GetHashCode() + Longitude.GetHashCode();
        }
    }

    public interface IMapOverlay
    {
        List<IMapDrawable> DrawableItems { get; set; }
        GeoPoint Point { get; }
        Point Offset { get; }
    }

    public class MapOverlay : IMapOverlay
    {
        private static long id_counter = 0;
        public long Id { private set; get; }

        public MapOverlay() { }

        public MapOverlay(GeoPoint point, Point offset)
        {
            DrawableItems = new List<IMapDrawable>(4);
            Offset = offset;
            Point = point;
            this.Id = id_counter++;
        }

        public bool AddElement(IMapDrawable drawable)
        {
            try
            {
                DrawableItems.Add(drawable);
            }
            catch(Exception)
            {
                return false;
            }
            return true;
        }

        public List<IMapDrawable> DrawableItems { get; set; }
        public GeoPoint Point { get; set; }
        public Point Offset { get; set; }
    }

    public class Segment
    {
        public string Text {get; set;}
        public string Distance {get; set;}
        public string Time { get; set; }
        public GeoPoint geoPoint { get; set; }
        public string RoadName { get; set; }
        public string FormattedText { get; set; }
        public string[] Notes { get; set; }
    }

    public class Route
    {
        public GeoPoint[] PolyLine {get; set;}
        public int[] Levels { get; set; }
        public Color Color { get; set; }
        public float LineWidth { get; set; }
    }

    public class Directions : Route
    {
        public Segment[] Segments { get; set; }
    }
}
